package com.sh.configs;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

@Configuration
public class VelocityConfig {
    @Bean
    public VelocityEngine velocityEngine() {
        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        velocityEngine.init();
        return velocityEngine;
    }

    @Bean
    public VelocityContext velocityContext() {
        return new VelocityContext();
    }

    @Bean(name = "deliveryMessage")
    public Template depositTemplate(VelocityEngine velocityEngine) {
        return velocityEngine.getTemplate("templates/vms/deliveryMessage.vm", "UTF-8");
    }

    @Bean(name = "fullDf")
    public DateFormat fullOf(){
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
    @Bean(name = "partDf")
    public DateFormat partOf(){
        return new SimpleDateFormat("yyyy-MM-dd  北京时间hh时");
    }
}
